package com.example.light.web.meeting.controller;

import com.example.light.web.meeting.entity.OaRoom;
import com.example.light.web.meeting.service.OaRoomService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
public class RoomController {
    @Autowired
    private OaRoomService oaRoomService;

    private OaRoom editRoom;

    @RequestMapping("addRoom")
    @ResponseBody
    String addRoom(OaRoom room, BindingResult result) {
        try {
            oaRoomService.addRoom(room);
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "失败";
    }

    @RequestMapping("toEditRoom")
    String toEditRoom(OaRoom room, BindingResult result, Model model) {
        if (room.getRoomId() != null) {
            editRoom = oaRoomService.querySingle(room.getRoomId(), model);
            return "meeting/meet_room/meeting_room_modify";
        }
        oaRoomService.addModel(model, editRoom);
        return "meeting/meet_room/meeting_room_modify";
    }

    @RequestMapping("editRoom")
    @ResponseBody
    String editRoom(OaRoom room,BindingResult result){
        try {
            oaRoomService.editRoom(room);
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "错误";
    }

    @RequestMapping("delRoom")
    @ResponseBody
    String delRoom(int[] delInfo){
        try {
            oaRoomService.delRoom(delInfo);
            return "成功";
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "失败";
    }
}
